In our own terms, a database is a system created to store and collect data that can be accessed and viewed easily. When creating efficient databases, we follow thenormal form.
Primary And Foreign Keys
The primary key is the data entry that defines the table. The foreign key is the data entry which is a primary key on another table.
First Normal Form
This states that one piece of data is in one column at all times.
In the two tables above, there is only one piece of data in each column. There is not multiple phone numbers in one cell, etc.
Second Normal Form
The table must already be in the first normal form. Each attribute must be dependant on the entire primary key
In these two tables, every "attribute" is dependant on the primary key, which is the Student ID. The students first and last name relies on the Student ID number. Furthermore the student ID is what tells us which student is in which block or course.
Third Normal Form
Each of the following data in the table is only dependent on the Primary Key.
Using the example from the First Normal Form 1....
The primary key for the first table is Student #
Reason? Without the Student number, we will not find the student's first or last name
The primary key for the second table in Phone ID, the Foreign Key is the Student # Reason? Without the phone ID, we will not know who the numbers will belong to The foreign key will "link" the two tables that contain the student # and we will move on to another characteristic of a database...
What happens when we need more complicated structures?
Relational Databases
How can we create tables for the following examples without breaking the normal form?
Families (parents and children)
Products and parts
Manufacturers and Products
Classes and Students
Customers and Invoices
There will be a lot of problems you may run into, like the following:
Some products might have only one data entry; another might have 20. How do you know how many fields to add?
What if the same component is used in a number of different products?
What if you wanted to find a particular component? You would have to search all those additional component fields, because you wouldn't know which one it might be in!
What if you wanted to produce a report listing all your components and their prices? That would be extremely difficult.
This is why we have relational databases. In our example, there is only two parts: Parts and Components. We will use the User and the UserPhoneNumber tables to explain how the basic user details would go to the UserPhoneNumber and each of the details will go into a record in the components table. We link the tables with the diamonds and arrows. These are called one to one and one to many relationships
Click the picture to see the link
One to many, One to One
1. What is a many to one relationship?
Many components can be related to one product. In our example, there are many UserPhoneNumbers for one UserID. So, to find all the components that make the product with the ID number 9687, you would search the tables for all records with the ID number. There might be only one or there might be many tables with the ID number.
2.. What is a Many to Many relationship?
This is when the same component can be used in a number of different products. Many components can be related to many products. here is another example:
The relations table would contain one record for each link between a product and a component. With this sort of structure, you can easily produce reports showing all the components belonging to a product, or all the products in which a particular component is used
Table of Contents
WHAT IS A DATABASE?
In our own terms, a database is a system created to store and collect data that can be accessed and viewed easily. When creating efficient databases, we follow the normal form.
Primary And Foreign Keys
The primary key is the data entry that defines the table. The foreign key is the data entry which is a primary key on another table.
First Normal Form
This states that one piece of data is in one column at all times.In the two tables above, there is only one piece of data in each column. There is not multiple phone numbers in one cell, etc.
Second Normal Form
The table must already be in the first normal form. Each attribute must be dependant on the entire primary keyIn these two tables, every "attribute" is dependant on the primary key, which is the Student ID. The students first and last name relies on the Student ID number. Furthermore the student ID is what tells us which student is in which block or course.
Third Normal Form
Each of the following data in the table is only dependent on the Primary Key.Using the example from the First Normal Form 1....
The primary key for the first table is Student #
Reason? Without the Student number, we will not find the student's first or last name
The primary key for the second table in Phone ID, the Foreign Key is the Student #
Reason? Without the phone ID, we will not know who the numbers will belong to
The foreign key will "link" the two tables that contain the student # and we will move on to another characteristic of a database...
What happens when we need more complicated structures?
Relational Databases
How can we create tables for the following examples without breaking the normal form?
There will be a lot of problems you may run into, like the following:
This is why we have relational databases. In our example, there is only two parts: Parts and Components. We will use the User and the UserPhoneNumber tables to explain how the basic user details would go to the UserPhoneNumber and each of the details will go into a record in the components table. We link the tables with the diamonds and arrows. These are called one to one and one to many relationships
One to many, One to One
1. What is a many to one relationship?
Many components can be related to one product. In our example, there are many UserPhoneNumbers for one UserID. So, to find all the components that make the product with the ID number 9687, you would search the tables for all records with the ID number. There might be only one or there might be many tables with the ID number.
2.. What is a Many to Many relationship?
This is when the same component can be used in a number of different products. Many components can be related to many products. here is another example:
The relations table would contain one record for each link between a product and a component. With this sort of structure, you can easily produce reports showing all the components belonging to a product, or all the products in which a particular component is used
Entity Relationship Diagrams
A database requires : Entity Relationship (ER) Diagrams
Rule 1
states that the primary key should not contain a value that is not real.Rule 2
states that any non-primary key is able to contain a unreal value.http://dictionary.reference.com/browse/database
http://www.google.ca/imgres?imgurl=http://www.whitemoorstudio.com/site_media/images/demo_rev01.png&imgrefurl=http://www.whitemoorstudio.com/en/database/&usg=__txjI_o8JThBvzH1IkEgX7vxiguo=&h=411&w=545&sz=37&hl=en&start=27&zoom=1&tbnid=WjLbb8AGCDpIYM:&tbnh=139&tbnw=184&ei=0e6ZTd2iA4LWtQPP49GCAw&prev=/images%3Fq%3Dentity%2Brelationship%2Bdiagrams%2Bdatabase%26um%3D1%26hl%3Den%26safe%3Dactive%26sa%3DN%26biw%3D1440%26bih%3D766%26tbs%3Disch:10%2C600&um=1&itbs=1&iact=rc&dur=341&oei=zu6ZTcz7B_DciALEv9idCQ&page=2&ndsp=30&ved=1t:429,r:8,s:27&tx=124&ty=43&biw=1440&bih=766